package com.tsc.springTemp.exception;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: chentl
 * @Date: 2025/09/14/10:59
 * @Description:
 */
public class CustomExceptionDemo {

    public static void main(String[] args) {
        UserService userService = new UserService();

        // 测试检查型异常
        try {
            User user = userService.findById(200);
            System.out.println("找到用户: " + user);
        } catch (UserNotFoundException e) {
            System.err.println("错误: " + e.getMessage());
        }

        // 测试非检查型异常
        try {
            userService.validateAge(-5);
        } catch (InvalidAgeException e) {
            System.err.println("错误: " + e.getMessage());
        }

        // 测试正常情况
        try {
            User user = userService.findById(50);
            System.out.println("找到用户: " + user);
            userService.validateAge(25);
            System.out.println("年龄验证通过");
        } catch (UserNotFoundException e) {
            System.err.println("错误: " + e.getMessage());
        }
    }
}
